package com.itheima.service.impl.pms;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.itheima.core.PageInfo;
import com.itheima.mapper.pms.PmsProductAttributeMapper;

import com.itheima.pojo.pms.PmsBrand;
import com.itheima.pojo.pms.PmsProductAttribute;
import com.itheima.pojo.pms.vo.ProductAttrInfoVo;
import com.itheima.service.pms.PmsProductAttributeService;

import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@DubboService
public class PmsProductAttributeServiceImpl extends ServiceImpl<PmsProductAttributeMapper, PmsProductAttribute>implements PmsProductAttributeService {
    @Autowired
    private PmsProductAttributeMapper pmsProductAttributeMapper;
    @Override
    public List<ProductAttrInfoVo> getProductAttrInfo(Long productCategoryId) {
        return pmsProductAttributeMapper.getProductAttrInfo(productCategoryId);
    }

    /**
     * 根据分类查询属性列表或参数列表
     * @param cid
     * @param type
     * @param pageSize
     * @param pageNum
     * @return
     */
    @Override
    public PageInfo getList(Long cid, Integer type, Integer pageSize, Integer pageNum) {

        Page<PmsProductAttribute> page=new Page<>(pageNum,pageSize);
        LambdaQueryWrapper<PmsProductAttribute> wrapper = new LambdaQueryWrapper<>();
       wrapper.eq(PmsProductAttribute::getProductAttributeCategoryId,cid);
       wrapper.eq(PmsProductAttribute::getType,type);



        Page<PmsProductAttribute> pmsBrandPage = this.page(page, wrapper);
        int total = (int)pmsBrandPage.getTotal();
        int current = (int) pmsBrandPage.getCurrent();

        //封装分页数据
        PageInfo pageInfo = new PageInfo();
        pageInfo.setPageNum(pageNum);
        pageInfo.setPageSize(pageSize);
        pageInfo.setTotal(total);
        pageInfo.setTotalPage(current);
        pageInfo.setList(pmsBrandPage.getRecords());

        return pageInfo;
    }

}
